package Pojo;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 客户类
 * 
 * @author 吴春明
 * 
 */
public class Customer {
	public String[] names = new String[100];
	public String[] year = new String[100];
	public String[] ismarry = new String[100];
	public Scanner input = new Scanner(System.in);
	public int dex;
	public int Z;

	/**
	 * 添加客户
	 */
	public void showAddName() {
		System.out.print("请输入客户的姓名:");
		String name1 = input.next();
		for (int i = 0; i < names.length; i++) {
			if (names[i] == null) {
				names[i] = name1;
				System.out.println("继续输入码？y/n");
				if (input.next().equals("y")) {
					showAddName();
					break;
				} else {
					showName();
					break;
				}

			} else {
				if (names[99] != null) {
					System.out.println("满了");
				}
			}
		}
	}

	/**
	 * 显示客户列表
	 */
	private void showName() {
		System.out.println("************************************");
		System.out.println("\t客户姓名列表\t");
		System.out.println("************************************");
		for (int i = 0; i < names.length; i++) {
			if (names[i] != null) {
				System.out.print(names[i] + "\t");
			} else {
				break;
			}
		}
		System.out.println("\n");
	}

	/**
	 * 查找客户姓名
	 * 
	 * @param oidname老名字
	 * @return
	 */
	public int getFindName(String oidname) {

		for (int i = 0; i < names.length; i++) {
			if (names[i] != null && names[i].equals("oidname")) {
				dex = i;
				return i;
			}

		}
		return -1;
	}

	/**
	 * 显示修改结果
	 * 
	 * @return
	 */
	public void showModifyName() {
		System.out.print("请输入要修改的客户姓名");
		String oidname = input.next();
		System.out.print("请输入修改后的姓名");
		String newname = input.next();
		System.out.println("\n****修改结果****");
		if (getFindName(oidname) == -1) {
			names[dex] = newname;
			System.out.println("找到并修改成功");
			showName();
		} else {
			System.out.println("修改失败");
			showName();
		}
	}

	/**
	 * 客户名排序
	 */
	public void showSortName() {
		System.out.println("****排序前****");
		for (int i = 0; i < names.length; i++) {
			if (names[i] != null) {
				System.out.print(names[i] + "\t");
			} else {
				System.out.println();
				break;
			}
		}
		System.out.println("****排序后****");
		String[] names1 = new String[getNameNull()];
		for (int i = 0; i < names.length; i++) {
			if (names[i] != null) {
				names1[i] = names[i];
			} else {
				break;
			}
		}
		Arrays.sort(names1);
		for (int i = 0; i < names1.length; i++) {
			System.out.print(names1[i] + "\t");
		}
		System.out.println("\n");
	}

	/**
	 * 客户总数
	 * 
	 * @return
	 */
	public int getNameNull() {
		for (int i = 0; i < names.length; i++) {
			if (names[i] == null) {
				Z = i;
				return Z;
			}
		}
		Z = 100;
		return Z;
	}

	/**
	 * 客户信息的添加
	 * 
	 * @return
	 */
	public void getAddCustmer() {
		System.out.println("请输入添加信息的客户姓名");
		if (getFindName(input.next()) == dex) {
			System.out.println("请输入年龄");
			year[dex] = input.next();
			System.out.println("是否结婚了?y/n");
			if (input.next().equals("y")) {
				ismarry[dex] = "true";
			} else {
				ismarry[dex] = "false";
			}
			System.out.println("继续输入码？y/n");
			if (input.next().equals("y")) {
				getAddCustmer();
			} else {
				showCusttmer();
			}
		} else {
			System.out.println("客户姓名不存在");
			showCusttmer();
		}
	}

	/**
	 * 客户信息的显示
	 * 
	 * @return
	 */
	public void showCusttmer() {
		for (int i = 0; i < names.length; i++) {
			if (names[i] != null && year[i] != null && ismarry[i] != null) {
				System.out.println(names[i] + "\t" + year[i] + "\t"
						+ ismarry[i]);
			} else {
				break;
			}
		}
	}

}
